package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.Ware;
import com.zoo.diannaopeijian.domain.WareParameterDetail;
import com.zoo.diannaopeijian.mapper.WareParameterDetailMapper;
import com.zoo.diannaopeijian.service.WareParameterDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 商品参数服务实现类
 */
@Service
public class WareParameterDetailServiceImpl implements WareParameterDetailService {
    @Resource
    private WareParameterDetailMapper wareParameterDetailMapper;


    @Override
    public boolean addWareParameterDetail(WareParameterDetail wareParameterDetail) {
        if (CheckUtil.allNullBeanCheck(wareParameterDetail)) {
            return true;
        }
        return wareParameterDetailMapper.insertSelective(wareParameterDetail) == 1;
    }

    @Override
    public List<Map> getWareParameterDetail(Integer wareId) {
        if (wareId == null) {
            throw new NullPointerException();
        }
        return wareParameterDetailMapper.selectWareParameterDetail(wareId);
    }

    @Override
    public boolean removeWareParameterDetail(WareParameterDetail wareParameterDetail) {
        if (CheckUtil.allNullBeanCheck(wareParameterDetail)) {
            throw new NullPointerException("wareParameterDetail不能全为空");
        }
        return wareParameterDetailMapper.delete(wareParameterDetail) == 1;
    }

    @Override
    public List<Ware> getParameterDetailWareWithPage(
            Ware ware,
            Page page,
            Integer componentId,
            List<Integer> componentParameterDetailIds) {
        if (page != null) {
            page.onPage();
        }
        return getParameterDetailWare(
                ware,
                componentId,
                componentParameterDetailIds);
    }

    @Override
    public List<Ware> getParameterDetailWare(
            Ware ware,
            Integer componentId,
            List<Integer> componentParameterDetailIds
    ) {
        return wareParameterDetailMapper.selectParameterDetailWare(
                ware,
                componentId,
                componentParameterDetailIds
        );
    }

    @Override
    public List<Ware> getFuzzyParameterDetailWareWithPage(
            Ware ware,
            Page page,
            Integer componentId,
            List<Integer> componentParameterDetailIds
    ) {
        if (page != null) {
            page.onPage();
        }
        return getFuzzyParameterDetailWare(
                ware,
                componentId,
                componentParameterDetailIds
        );
    }

    @Override
    public List<Ware> getFuzzyParameterDetailWare(
            Ware ware,
            Integer componentId,
            List<Integer> componentParameterDetailIds
    ) {
        return wareParameterDetailMapper.getFuzzyParameterDetailWare(
                ware,
                componentId,
                componentParameterDetailIds
        );
    }
}
